<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加进思用户</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/product/productManage/addProduct/product-addProduct.css">
    <style>

    </style>
</head>
<body>
<div class="box layui-form">
    <!--用户列表-->
    <div class="list">
        <div class="list-left">
            <div class="list-left-left"></div>
            <p class="list-left-right">添加进思用户</p>
        </div>
        <div class="list-right">
            <div class="list-right-left layui-btn layui-icon layui-icon-refresh" onclick="refresh()">&nbsp;刷新</div>
            <div class="list-right-right layui-btn layui-icon layui-icon-left" id="goBack">&nbsp;返回</div>
        </div>
    </div>

    <div class="box2">
<div style="margin-left: -350px">
        <div class="layui-row" style="width: 800px; height: 80px; text-align: center; margin-top: 50px; margin-left: 220px;">
            <div style="float: left;">
                <div class="layui-row">
                    <label class="layui-form-label">用户账号:</label>
                    <div class="layui-input-inline">
                        <input id="account" type="tel" name="account" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
                    </div>
                </div>
            </div>
        </div>

        <div style="width: 800px; height: 80px; text-align: center; margin-left: 25px;">
            <div class="layui-inline">
                <label class="layui-form-label">用户昵称:</label>
                <div class="layui-input-inline">
                    <input id="nickname" type="tel" name="nickname" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
                </div>
            </div>
        </div>

        <div style="width: 800px; height: 80px;margin-left: 220px;">
            <div class="layui-inline">
                <label class="layui-form-label">用户头像:</label>
                <div class="layui-input-inline">
                    <input type="button" id="upLoad"  name="shangchuan" lay-verify="required|phone" autocomplete="off" class="layui-btn" value="上传图片" >
                    <input id="avatarUrl" type="text"  name="avatarUrl" value="文件路径" hidden>
                </div>
            </div>
        </div>

        <div style="width: 800px; height: 80px;margin-left: 220px;">
            <div class="layui-inline">
                <label class="layui-form-label">预览图:</label>
                <div class="layui-input-inline">
                    <div id="imgurls" style="width: 400px;height: 140px;border: 1px solid #eee;"></div>
                </div>
            </div>
        </div>

        <div class="body-box2-div1"  style="width: 800px; height: 100px; text-align: center; margin-left: 220px;margin-top: 100px">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">用户介绍:</label>
                <div class="layui-input-block">
                    <textarea id="remarks" name="remarks" placeholder="请输入内容" class="layui-textarea" style="width: 400px;"></textarea>
                </div>
            </div>
        </div>

        <div class="body-box2-div1" style="margin-top:30px;">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">个人标签:</label>
                <div class="layui-input-block">
                    <textarea id="freestyle" name="freestyle" placeholder="请输入内容" class="layui-textarea" style="width: 400px;"></textarea>
                </div>
            </div>
        </div>

        <div class="body-box2-div2" style="margin-top: 30px;">
            <div class="layui-inline">
                <label class="layui-form-label">用户编号:</label>
                <div class="layui-input-inline">
                    <input id="userCode" name="userCode" type="tel" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
                </div>
            </div>
        </div>

        <div class="body-box2-div2">
            <div class="layui-inline">
                <label class="layui-form-label">身份证号:</label>
                <div class="layui-input-inline">
                    <input id="idCard" type="tel" name="idCard" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
                </div>
            </div>
        </div>
        <div class="body-box2-div2">
            <div class="layui-inline">
                <label class="layui-form-label">邮箱:</label>
                <div class="layui-input-inline">
                    <input id="email" type="tel" name="email" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
                </div>
            </div>
        </div>
</div>
<div style="position:absolute;left: 700px;top:70px;float: left">
    <div class="body-box2-div2" style="width: 800px; height: 80px; text-align: center; margin-left: 25px;margin-top: 30px">
        <div class="layui-inline">
            <label class="layui-form-label">消费金额:</label>
            <div class="layui-input-inline">
                <input id="consumption" type="tel" name="consumption" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>
    <div class="body-box2-div2">
        <div class="layui-inline">
            <label class="layui-form-label">学习时长:</label>
            <div class="layui-input-inline">
                <input id="studyDate" type="tel" name="studyDate" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>
    <div class="body-box2-div2">
        <div class="layui-inline">
            <label class="layui-form-label">求职意向:</label>
            <div class="layui-input-inline">
                <input id="intention" type="tel" name="intention" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>
    <div style="width: 800px; height: 80px; text-align: center; margin-left: 25px;">
        <div class="layui-inline">
            <label class="layui-form-label">手机号:</label>
            <div class="layui-input-inline">
                <input id="phone" type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>

    <div class="layui-row" style="width: 800px; height: 80px; text-align: center; margin-left: 220px;">
        <div style="float: left;">
            <div class="layui-row">
                <label class="layui-form-label">所学专业:</label>
                <div class="layui-input-inline">
                    <input id="profession" type="tel" name="profession" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
                </div>
            </div>
        </div>
    </div>

    <div style="width: 800px; height: 80px; text-align: center; margin-left: -35px;">
        <div class="layui-inline">
            <label class="layui-form-label">是否毕业:</label>
            <div class="layui-input-block">
                <input type="radio" lay-filter="type" name="type" value="未毕业" title="未毕业">
                <input type="radio" lay-filter="type" name="type" value="已毕业" title="已毕业" checked>
            </div>
        </div>
    </div>

    <div style="width: 800px; height: 80px; text-align: center; margin-left: 25px;">
        <div class="layui-inline">
            <label class="layui-form-label">学习内容:</label>
            <div class="layui-input-inline">
                <input id="studyContent" type="tel" name="studyContent" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>

    <div class="body-box2-div2" style="margin-top: 10px;">
        <div class="layui-inline">
            <label class="layui-form-label">量化积分:</label>
            <div class="layui-input-inline">
                <input id="integration" name="integration" type="tel" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>

    <div class="body-box2-div2" style="margin-top: 10px;">
        <div class="layui-inline">
            <label class="layui-form-label">入学时间:</label>
            <div class="layui-input-inline">
                <input id="entranceDate" name="entranceDate" type="tel" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>

    <div class="body-box2-div2" style="margin-top: 10px;">
        <div class="layui-inline">
            <label class="layui-form-label">毕业时间:</label>
            <div class="layui-input-inline">
                <input id="graduationDate" name="graduationDate" type="tel" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>

    <div class="body-box2-div2">
        <div class="layui-inline">
            <label class="layui-form-label">备注:</label>
            <div class="layui-input-inline">
                <input id="remarkss" type="tel" name="remarkss" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width: 300px;">
            </div>
        </div>
    </div>
</div>

        <div style="width: 800px; height: 80px; margin-left: 300px;">
            <input value="提交用户" class="layui-btn" id="submitUser"/>
        </div>
        <input type="text" id="currentTime" hidden/>
    </div>
</div>
</body>
<script>
    layui.use(["jquery","layer","form",'upload','laydate'],function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var laydate=layui.laydate;
        var upload = layui.upload;

        laydate.render({
            elem: '#entranceDate',
            type: 'datetime',
            trigger: 'click'
        })

        laydate.render({
            elem: '#graduationDate',
            type: 'datetime',
            trigger: 'click'
        })

        var type=3;
        form.on("radio(type)",function (data) {
            if (data.value == "已毕业"){
                type = 3;
            }else {
                type = 2;
            }
        });

        upload.render({
            elem:"#upLoad",
            url:"/Upload/upload",
            field:'file',
            accept:'file',
            done:function(res){
                $('#imgurls').append("<img style='width: 140px;height: 140px;' src='"+res.data+"'>");
                $('#avatarUrl').val(res.data);
            },
        })

        //现在时间
        function getTime(){
            var date=new Date();
            var year=date.getFullYear();
            var month=date.getMonth()+1;
            var day=date.getDate();
            var hour=date.getHours();
            var minute=date.getMinutes();
            var second=date.getSeconds();
            var dateStr = year+"-"+zeroFilling(month)+"-"+zeroFilling(day)+" "+zeroFilling(hour)+":"+zeroFilling(minute)+":"+zeroFilling(second);
            $('#currentTime').val(dateStr);
        }
        function zeroFilling(data){
            if(data<10){
                data="0"+data;
            }
            return data;
        }

        $("#submitUser").click(function () {
            getTime();
            var userCode = $("#userCode").val();
            var user = JSON.parse(localStorage.getItem('user'));
            var createId = user.data.userId;

            $.ajax({
                url:"/JsBeforeUser/getJsBeforeUser",
                data:{},
                type:'post',
                dataType:"json",
                success:function (data) {
                    var arr = [];
                    for (var i = 0; i < data.data.length ; i++) {
                        arr.push(data.data[i].userCode);
                    }
                    var num = 0;
                    for (var i = 0; i <= arr.length ; i++) {
                        if (arr[i] == userCode) {
                            layer.msg("已存在用户");
                            return ;
                        }
                        if (arr[i] != userCode&&arr.length!=0) {
                            num++;
                        }
                        if (num == arr.length) {
                            var param = {
                                "photoImg":'无',
                                'phone':$("#phone").val(),
                                "account":$("#account").val(),
                                "nickname":$("#nickname").val(),
                                'userCode':$("#userCode").val(),
                                'avatarUrl':$("#avatarUrl").val(),
                                'studyDate':$("#studyDate").val(),
                                "status":2,
                                "freestyle":$("#freestyle").val(),
                                'idCard':$("#idCard").val(),
                                "email":$("#email").val(),
                                'remarks':$("#remarks").val(),
                                'intention':$("#intention").val(),
                                'consumption':$("#consumption").val(),
                                'createId':createId,
                                'createDate':$("#currentTime").val()
                            }
                            $.ajax({
                                url:"/JsBeforeUser/addJsBeforeUser",
                                data:param,
                                type:'post',
                                dataType:'json',
                                success:function (data) {
                                    $.ajax({
                                        url:"/JsBeforeUser/getJsBeforeUserId",
                                        data:{'userCode':userCode},
                                        type:'post',
                                        dataType:'json',
                                        success:function (data) {
                                            var user=JSON.parse(localStorage.getItem("user"));
                                            var params={
                                                'userId':data.data.userId,
                                                'profession':$("#profession").val(),
                                                'type':type,
                                                'studyContent':$("#studyContent").val(),
                                                'integration':$("#integration").val(),
                                                'entranceDate':$("#entranceDate").val(),
                                                'graduationDate':$("#graduationDate").val(),
                                                'remarks':$("#remarkss").val(),
                                                'createId':user.data.userId,
                                                'createDate':$('#currentTime').val()
                                            }
                                            $.ajax({
                                                url:"/JsBeforeUser/addJsUserDevelopment",
                                                data:params,
                                                type:'post',
                                                dataType:'json',
                                                success:function(){
                                                    window.location.href="user-list.html";
                                                }
                                            })
                                        }
                                    })
                                }
                            })
                        }
                    }
                }
            })
        })

        //返回按钮
        $('#goBack').click(function () {
            window.location.href="/user/leadingUser/leadingUserList/user-list.html";
        });

    })
</script>
</html>